package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.system.domain.PEvaluate;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PEvaluateVo;
import com.ruoyi.system.domain.bo.PEvaluateBo;
import com.ruoyi.system.service.IPEvaluateService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 用户评价咨询师Controller
 *
 * @author ruoyi
 * @date 2022-07-22
 */
@Validated
@Api(value = "用户评价咨询师控制器", tags = {"用户评价咨询师管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/evaluate")
public class PEvaluateController extends BaseController {

    private final IPEvaluateService iPEvaluateService;

    /**
     * 查询用户评价咨询师列表
     */
    @ApiOperation("查询用户评价咨询师列表")
    @SaCheckPermission("system:evaluate:list")
    @GetMapping("/list")
    public TableDataInfo<PEvaluate> list(PEvaluate bo, PageQuery pageQuery) {
        return iPEvaluateService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户评价咨询师列表
     */
    @ApiOperation("导出用户评价咨询师列表")
    @SaCheckPermission("system:evaluate:export")
    @Log(title = "用户评价咨询师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PEvaluateBo bo, HttpServletResponse response) {
        List<PEvaluateVo> list = iPEvaluateService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户评价咨询师", PEvaluateVo.class, response);
    }

    /**
     * 获取用户评价咨询师详细信息
     */
    @ApiOperation("获取用户评价咨询师详细信息")
    @SaCheckPermission("system:evaluate:query")
    @GetMapping("/{id}")
    public R<PEvaluate> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(iPEvaluateService.queryById(id));
    }

    /**
     * 新增用户评价咨询师
     */
    @ApiOperation("新增用户评价咨询师")
    @SaCheckPermission("system:evaluate:add")
    @Log(title = "用户评价咨询师", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PEvaluateBo bo) {
        return toAjax(iPEvaluateService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改用户评价咨询师
     */
    @ApiOperation("修改用户评价咨询师")
    @SaCheckPermission("system:evaluate:edit")
    @Log(title = "用户评价咨询师", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PEvaluateBo bo) {
        return toAjax(iPEvaluateService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除用户评价咨询师
     */
    @ApiOperation("删除用户评价咨询师")
    @SaCheckPermission("system:evaluate:remove")
    @Log(title = "用户评价咨询师", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPEvaluateService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
